﻿//using Services.Equ.PcapCommunication.Abstract;
//using SharpPcap;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Net.NetworkInformation;
//using System.Text;
//using System.Threading.Tasks;

//namespace Services.Equ.PcapCommunication
//{
//    /// <summary>
//    /// 升级设备通讯抽象类
//    /// </summary>
//    public class WriteFileCommunication : AbstractPcapCommunication<bool>
//    {
//        public FileInfo UpgradeFile { get; set; }
//        private byte[] partFile= [];
//        public WriteFileCommunication(FileInfo upgradeFile, PhysicalAddress destinationMac, string password, ILiveDevice device) : base(destinationMac, password, device)
//        {
//            UpgradeFile = upgradeFile;
//            DcpType = 0x40002;
//            RpcType = 1;
//            OpType = 4;
//        }
//        public override async Task<List<bool>> GetCommunicationResult()
//        {
//            List<bool> result= [];
//            using(var stream= UpgradeFile.OpenRead())
//            {
//                long byteSize = 1300;
//                long pos = stream.Position;
//                long streamLength = stream.Length - pos;
//                byteSize = 1300 <= streamLength ? byteSize : streamLength;
//                partFile= new byte[byteSize];
//                while (stream.Read(partFile,0, partFile.Length) > 0)
//                {
//                    result =await RetryFunction(base.GetCommunicationResult,t=>t.Any(t=>true));
//                    if (!result.Any(t => t))
//                    {
//                        break;
//                    }
//                    SeqId++;
                    
//                }
//            }
//            return result;
//        }
//        public override byte[] CreateBlockData()
//        {
//            return partFile;
//        }
//        public override byte[] CreateBlock()
//        {
//            return CreateBlockData();
//        }

//        public override bool ConvertData2Result(byte[] bytes)
//        {
//            return bytes[59] == 0;
//        }
//        public override bool IsResponse(byte[] bytes)
//        {
//            if (bytes.Length != 96)
//            {
//                return false;
//            }
//            if (base.IsResponse(bytes))
//            {
//                var seqBytes = bytes[84..88];
//                int seq = BitConverter.ToInt32(seqBytes.Reverse().ToArray());
//                return seq == SeqId;
//            }
//            return false;
//        }
//    }
    
//}
